'use strict';

const db = uniCloud.database();
const add_db = db.collection('appointment');
exports.main = async (event, context) => {
	const data = JSON.parse(event.data);
	let exit_yy = await add_db.where({ 'yyrq': data[4].yyrq ,'yysj': data[5].yysj}).count();
	if (exit_yy.total == 0){
		const AddResult = await add_db.add({
		  user: data[0].user,
		  notes: data[1].notes,
		  lfs: data[2].lfs,
		  xm: data[3].xm,
		  yyrq: data[4].yyrq,
		  yysj: data[5].yysj,
		  create_time: new Date().getTime(),
		})
		return {
			code: 0,
			msg: '预约成功'
			}
		
	}else{
		return {
			code: -2,
			msg: '该时间已有人预约,请重新选择时间'
		}
	}
};
